package com.example.win.android_banduyujia;

import android.app.Application;
import android.content.pm.PackageManager;

import com.example.win.android_banduyujia.database.DBHelper;

/**
 * Created by Win on 2015/8/13.
 */
public class BanDuApp extends Application {

    private static final String  LOG_TAG=BanDuApp.class.getSimpleName();
    private static BanDuApp mInstance;
    private boolean isFirstLoadTags = true;

    public BanDuApp() {
        mInstance = this;
    }

    public static BanDuApp getContext() {
        return mInstance;
    }

    public boolean getIsFirstLoadTags() {
        return isFirstLoadTags;
    }

    public void setIsFirstLoadTags(boolean isFirst) {
        this.isFirstLoadTags = isFirst;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        DBHelper.init(this);

    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    public static String  getAppName(){
        return   getStringByResId(R.string.app_name);
    }

    private static String getStringByResId(int resId) {
        return getContext().getString(resId);
    }

    private static String getStringByResId(int resId, Object... formatArgs) {
        return getContext().getString(resId, formatArgs);
    }

    private static int getColorByResId(int resId) {
        return getContext().getResources().getColor(resId);
    }

    private static float getDimensionByResId(int resId) {
        return getContext().getResources().getDimension(resId);
    }

    private static int imageNameToResId(String imageName) {
        return getContext().getResources().getIdentifier(imageName, "drawable", getContext().getPackageName());
    }

    private static int resToResId(String imageName) {
        return getContext().getResources().getIdentifier(imageName, "raw", getContext().getPackageName());
    }

    public static String getAppVersionCode(){
        int  code = 0;
         try{
            code = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_META_DATA).versionCode;
         }catch (PackageManager.NameNotFoundException e){

         }
        return  String.valueOf(code);
    }

    public static String getAppVersion(){
        String version = " ";
        try{
            version = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(),PackageManager.GET_META_DATA).versionName;
        }catch (PackageManager.NameNotFoundException e){

        }
        return  version;
    }
}
